﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyLib.MyBase.MyWeb;
using MyChocCuoi.Setting;
using MyLoad.LoadStatic;
using System.Data;
using MyChocCuoi.DB.Member;
using DBMember = MyChocCuoi.DB.Member;
using MyLib.MyUtility;
namespace MyLoad.LoadMember
{
    public class LProfile : MyLoadWeb
    {
        int MemberID = 0;
        public MemberObject mMemberObj = new MemberObject();
        public LProfile(MyASHX CurrentPage)
        {
            this.CurrentPage = CurrentPage;
            TemplatePath = "~/Templates/Member/Profile.html";
            Init();
        }

        // Hàm trả về chuỗi có chứa mã HTML
        protected override string BuildHTML()
        {
            try
            {
                if (WebSetting.MemberLogined.IsNull)
                {
                    CurrentPage.Response.Redirect(WebSetting.LoginURL);
                    return string.Empty;
                }

                if (CurrentPage.Request.QueryString["mid"] != null)
                    int.TryParse(CurrentPage.Request.QueryString["mid"], out MemberID);

                if (MemberID <= 0 || MemberID != WebSetting.MemberLogined.MemberID)
                {
                    LError.RedirectErrorLink(LError.ErrorType.InvalidURL);
                    return string.Empty;
                }
                DBMember.Member mMember = new DBMember.Member();

                DataTable mTable = mMember.Select(1, MemberID.ToString());
                if (mTable.Rows.Count < 1)
                    return string.Empty;


                mMemberObj = MemberObject.Convert(mTable);

                string[] arr = { mMemberObj.MemberID.ToString(), mMemberObj.MemberName, mMemberObj.Email };
                return LoadTemplateByArray(TemplatePath,arr);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
